﻿using Core.Entities.EQ;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Infrastructure.Data.Configurations.EQ
{
    /// <summary>
    /// 设备信息配置
    /// </summary>
    public class DeviceConfiguration : IEntityTypeConfiguration<Device>
    {
        public void Configure(EntityTypeBuilder<Device> builder)
        {
            // 设置表名
            builder.ToTable("EQ_Device");

            // 配置主键
            builder.HasKey(d => d.Id);

            // 属性配置
            builder.Property(d => d.Id)
                .HasColumnName("ID")
                .HasMaxLength(50);

            builder.Property(d => d.DevCode)
                .HasColumnName("DEV_CODE")
                .HasMaxLength(50);

            builder.Property(d => d.DevName)
                .HasColumnName("DEV_NAME")
                .HasMaxLength(50);

            builder.Property(d => d.ProductionLine)
                .HasColumnName("ProductionLine")
                .HasMaxLength(255);

            builder.Property(d => d.BuyTime)
                .HasColumnName("BuyTime")
                .HasColumnType("datetime2(7)");

            builder.Property(d => d.DevSpec)
                .HasColumnName("DEV_SPEC")
                .HasMaxLength(50);

            builder.Property(d => d.DevStatus)
                .HasColumnName("DEV_STATUS")
                .HasMaxLength(50);

            builder.Property(d => d.CreateTime)
                .HasColumnName("CREATETIME")
                .HasColumnType("datetime2(7)");

            //builder.Property(d => d.IsDeleted)
            //    .HasColumnName("IsDeleted")
            //    .HasDefaultValue(false);

            builder.Property(d => d.DevManager)
                .HasColumnName("DEV_Manager")
                .HasMaxLength(255);

            // 索引配置
            builder.HasIndex(d => d.DevCode)
                .HasDatabaseName("IX_EQ_Device_DEV_CODE");

            builder.HasIndex(d => d.DevName)
                .HasDatabaseName("IX_EQ_Device_DEV_NAME");

            builder.HasIndex(d => d.ProductionLine)
                .HasDatabaseName("IX_EQ_Device_ProductionLine");

            // 软删除配置
            //builder.HasQueryFilter(d => !d.IsDeleted);
        }
    }
}